package com.company.exp2.event.impl;

import com.company.exp2.context.Context;
import com.company.exp2.event.Event;
import com.company.exp2.frame.Frame;
import com.company.exp2.station.Station;
import com.company.exp2.typeEnum.EventType;

/**
 * @author dyy
 */
public class ChannelForbiddenEvent extends Event {

    /**
     * @param timestamp         事件发生的时间戳
     * @param associatedStation 引发信道关闭的传输帧的源站
     */
    public ChannelForbiddenEvent(long timestamp, Station associatedStation) {
        super(timestamp, associatedStation);
    }

    @Override
    public void occur() {
        Context currentContext = Context.currentContext;
        Frame currentTransmittingFrame = currentContext.getCurrentTransmittingFrame();
        // 如果二者相等，说明并没有发生碰撞, 应该调用当前传输帧的 onTransmitting 方法
        if (currentContext.hasNotCollided()) {
            currentTransmittingFrame.onTransmitting(getTimestamp());
        }
        currentContext.onChannelForbidden(getTimestamp());
    }

    @Override
    public EventType getEventType() {
        return EventType.CHANNEL_FORBIDDEN;
    }
}
